﻿using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Sla;
using MediatR;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Sla
{
    public class QuerySlaughterHandler : IRequestHandler<QuerySlaughterCommand, ApiResult<List<Slaughter>>>
    {
        private readonly IBaseRepository<Slaughter> slaRep;

        public QuerySlaughterHandler(IBaseRepository<Slaughter> slaRep)
        {
            this.slaRep = slaRep;
        }
        public Task<ApiResult<List<Slaughter>>> Handle(QuerySlaughterCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Slaughter>> result = new ApiResult<List<Slaughter>>();
            var list = slaRep.GetAll().Where(x => x.ProductId == request.ProductId);
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
